<?php

namespace App\model;

use support\Model;

class GuildLevelUp extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'guild_level_up';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = true;

    protected $dateFormat = 'U';

    // 定义一个访问器，用于格式化输出
    public function getCreatedAtAttribute($value)
    {
        return date('Y-m-d H:i:s', strtotime($value));
    }

    public function getLevelConfig($level)
    {
        $data = $this->where('level', $level)->first();
        return $data ? $data->toArray() : [];
    }

    public function getPeopleLimitNum($level)
    {
        $config = $this->getLevelConfig($level);
        return $config['limit_num'] ?? 0;
    }

    public function getMaxLevel()
    {
        $level = $this->orderBy('level', 'desc')->limit
        (1)->value('level');
        return intval($level);

    }


}
